package com.briup.ch04;

import java.util.Arrays;

public class Test8 {
    //可变参数实现多个值的平均数
    public static double getAvg(int... arr)
    {
        if(arr.length<=0)
        {
            return 0.0;
        }
        double sum=0.0;
        for (int num:arr) {
            sum+=num;
        }
        return sum;
    }
    public static void test(int... arr)
    {
        System.out.println(Arrays.toString(arr));
    }

    public static void main(String[] args) {
        int[] arr={1,2,3,4,5};
        double avg=getAvg(1,2,3,4);
        System.out.println(getAvg());
        System.out.println(getAvg(arr));
        System.out.println(avg);
        int a=1,b=3,c=8;
        System.out.println(getAvg(a,b,c));
        test(1,2,3,4);
    }
}
